package com.smw.config;

import com.smw.convert.MyConvert;
import com.smw.myinterceptor.MyInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //registry.addViewController( "/" ).setViewName( "forward:/login.html" );
        //registry.setOrder(Ordered.HIGHEST_PRECEDENCE );
        super.addViewControllers( registry );
    }
    //添加自定义转换器
    @Override
    public void addFormatters(FormatterRegistry registry) {
        //添加字符串转换Date的自定义转换器
        registry.addConverter(new MyConvert());
        super.addFormatters(registry);
    }
    @Bean
    public MyInterceptor getInterceptor() {
        return new MyInterceptor() ;
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getInterceptor())//将自定义的拦截器配置到项目
                .addPathPatterns("/order/queryAll");//拦截器拦截哪些请求
        //    .excludePathPatterns("/","user/login","toReg","user/reg","user/code","/js/jquery-3.5.1.min.js");//开绿色通道

        super.addInterceptors(registry);
    }
}
